package com.epam.edu.task03.parser;

import com.epam.edu.task03.dances.Dance;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.File;
import java.util.List;
import org.apache.log4j.Logger;

/**
 * Created with IntelliJ IDEA.
 * User: Zhanna_Mukanova
 * Date: 9/17/13
 * Time: 5:09 PM
 * To change this template use File | Settings | File Templates.
 */
public class XMLParserSAX implements ParserFactory {
    private Logger logger = Logger.getLogger(XMLParserSAX.class);

    public void getDancesDatas() {
        logger.info("________________XMLParserSAX_____________________");
        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
        try {
            SAXParser saxParser = saxParserFactory.newSAXParser();
            SAXHandler handler = new SAXHandler();
            saxParser.parse(new File("src/main/resources/dances.xml"), handler);
            List<Dance> danceList = handler.getDances();
            for (Dance dance : danceList)
                logger.info(dance.toString());
        } catch (Exception exception) {
            logger.error(exception.getMessage());
        }
    }
}
